/**
 *
 * @title modal组件有弹框的组件表现行为
 * @description popover、下拉、日期等组件弹框默认渲染在modal上
 *
 */

import React, { Component } from 'react';
import { base, high, ajax, toast } from 'nc-lightapp-front';
import Contract from '../Contract/index'
const { NCModal, NCButton, NCTreeNode, NCTreeSelect, NCRadio,NCCheckbox  } = base;
const { Header: ModalHeader, Body: ModalBody, Footer: ModalFooter } = NCModal;
const { Refer } = high;
const NCRadioGroup = NCRadio.NCRadioGroup;
import sendemail from '../../request-functions/sendemail';

class QysChoose extends Component {
    constructor(props) {
        super(props);
        this.state = {
            showModal: false,
            refcode:'001',
            list: {
                glbdef13: "01",
                flag: false,
                glbdef1: "",
                glbdef2: "",
                glbdef3: "",
                glbdef4: "",
                glbdef5: "",
                glbdef6: "",
                glbdef7: "",
                glbdef8: "",
                glbdef9: "",
                glbdef10: "",
                glbdef11: "",
                glbdef12: "",
                begindate: "",
                currentName: "",
                begindate: "",
                mobile: '',
                mamName: '',
                name: ''
            },
            isBtnFlag: ''
        };
        this.onClose = this.onClose.bind(this);
    }
    onChange = (value) => {
        debugger
        this.props.updateState({
            QysChooseModalValue: value
        });
        this.setState({
            refcode:value.refcode
        })
    }

    onOk(refObj) {

        if (refObj.refpk == undefined) {
            //请选择合同
            toast({ content: '请选择合同', color: 'warning' });//错误消息
            return;
        }

        this.props.updateState({
            QysChooseModalVisible: false
        });

        //先获取
        let checkRows = this.props.editTable.getCheckedRows('ncc600704list');

        let pk_psndocs = [];

        checkRows.map((item) => {
            pk_psndocs.push(item.data.values.pk_psndoc.value);
        });

        let data = {
            value: refObj.refpk,
            pk_psndocs: pk_psndocs
        }

        ajax({
            url: '/nccloud/hrhi/psnentrymgt/qysLxOper.do',
            data: data,
            success: (res) => {
                //原来按钮的功能转移到这儿发动
                this.props.updateState({
                    switchToDocModalVisible: true
                });
            },
            error: (res) => {
                toast({ content: res.message, color: 'danger' });//错误消息
            }
        })
    }

    onClose() {
        this.props.updateState({
            QysChooseModalVisible: false
        });
        this.setState({
            isBtnFlag: ''
        })
    }
    onRadioChange = (value) => {
        console.log("当前选择了模板===", value)
        this.getDetail(value);
        this.setState({
            isBtnFlag: '01'
        })
    };
    close2 = () => {
        this.setState({
            glbdef13: '01',
            showModal: false,
        })
    };
    showsxs = () => {
        
    }
    dialogSure = () => {
        console.log("点击确定保存=====")
        this.setState({
            showModal: false,
            isBtnFlag:''
        })
    };
    // 获取当前人offer信息
    getDetail = async (obj) => {
        let data = this.props.editTable.getCheckedRows('ncc600704list', true);
        let postData = {};
        let pk_psndoc = [];
        data.map((item) => {
            if (item && item.data && item.data.values && item.data.values.pk_psndoc && item.data.values.pk_psndoc.value) {
                pk_psndoc.push(item.data.values.pk_psndoc.value);
            }
        });
        if (pk_psndoc.length == 0) {
            toast({
                color: 'warning',
                content: "请先选择数据！"
            });
            return;
        }
        postData["pk_psndoc"] = pk_psndoc[0];
        try {
            let res = await sendemail(postData, 6);
            if (res.success) {
                toast({
                    color: 'success',
                    content: '请求成功'/* 国际化处理： 保存成功*/
                });
                this.setState({
                    list: {
                        currentName: res.data.name,
                        glbdef1: res.data.glbdef1,
                        glbdef2: res.data.glbdef2,
                        glbdef3: res.data.glbdef3,
                        glbdef4: res.data.glbdef4,
                        glbdef5: res.data.glbdef5,
                        glbdef6: res.data.glbdef6,
                        glbdef7: res.data.glbdef7,
                        glbdef8: res.data.glbdef8,
                        glbdef9: res.data.glbdef9,
                        glbdef10: res.data.glbdef10,
                        glbdef11: res.data.glbdef11,
                        glbdef12: res.data.glbdef12,
                        begindate: res.data.begindate,
                        mamName: res.data.mamName,
                        mobile: res.data.mobile,
                        glbdef13: obj,
                        name: res.data.name
                    }
                }, () => {
                    this.setState({
                        showModal: true,
                        list: { ...this.state.list }
                    })
                })
            } else {
                toast({
                    color: 'error',
                    content: res.data.msg || "请求失败"/* 国际化处理： 保存成功*/
                });
            }
        }
        catch (e) {
        }
    }
    render() {
        console.log(this.state.list)
        debugger

        const { QysChooseModalVisible, QysChooseModalValue, modal } = this.props;
        return (
            <div>
                <NCModal
                    show={QysChooseModalVisible}
                    onHide={this.onClose}
                //  bodyStyle={{ height: '700px' }}
                >
                    <ModalHeader closeButton={true} draggable={true}>
                        <span>选择签约合同</span>
                    </ModalHeader>
                    <ModalBody style={{ textAlign: 'center' }}>
                        <div style={{ width: 360, display: 'inline-block' }}>
                            <Refer
                                placeholder="合同类型"
                                refType="grid"
                                refName="合同类型"
                                refCode="hrhi.ref.qysChooseRef"
                                // type="dropDown"
                                /* 
                                queryCondition={() => {
                                    // return { parentbilltype: 'HTNZ' }; // 根据单据类型过滤
                                }} */
                                queryGridUrl="/nccloud/hrhi/ref/qysChooseRef.do"
                                value={QysChooseModalValue}
                                isMultiSelectedEnabled={false}
                                columnConfig={[{ name: ['编码', '名称'], code: ['refcode', 'refname'] }]}
                                isShowUnit={false}
                                onChange={this.onChange}
                            />
                            {/* 查看offer模板 */}
                            <NCModal show={this.state.showModal} onHide={this.close2} size={"xlg"}>
                                <NCModal.Header closeButton>
                                    <NCModal.Title>成都新潮传媒集团任用邀请函</NCModal.Title>
                                </NCModal.Header>
                                <NCModal.Body>
                                    <Contract
                                        {...this.props}
                                        list={this.state.list}
                                    >
                                    </Contract>
                                </NCModal.Body>
                            </NCModal>
                            {/* selectedValue={this.state.list.glbdef13} */}
                            <NCRadioGroup
                                name='language'
                                onChange={this.onRadioChange}
                                style={{textAlign:'left'}}
                            >{
                                // 普通人员(销售人员)
                                this.state.refcode == '001'?
                                <div>
                                     <NCRadio value='00101' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>1.入职-附件14劳动合同-新版-新入职员工（点击预览）</NCRadio>
                                     <NCRadio value='00102' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>2.入职-附件16保密协议（全员）（点击预览）</NCRadio>
                                     <NCRadio value='00103' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>3.入职-竞业限制协议（全员版）（点击预览）</NCRadio>
                                     <NCRadio value='00104' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>4.入职-新潮传媒集团员工手册（点击预览）</NCRadio>
                                     <NCRadio value='00105' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>5.入职-经营人员薪酬确认单（点击预览）</NCRadio>
                                </div>:
                                // 普通人员（服务，技术人员）
                                 this.state.refcode == '002'?
                                 <div>
                                     <NCRadio value='00101' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>1.入职-附件14劳动合同-新版-新入职员工（点击预览）</NCRadio>
                                     <NCRadio value='00102' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>2.入职-附件16保密协议（全员）（点击预览）</NCRadio>
                                     <NCRadio value='00103' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>3.入职-竞业限制协议（全员版）（点击预览）</NCRadio>
                                     <NCRadio value='00104' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>4.入职-新潮传媒集团员工手册（点击预览）</NCRadio>
                                     <NCRadio value='00205' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>5.入职-非经营人员薪酬确认单（点击预览）</NCRadio>
                                </div>:
                                // 高管销售人员
                                this.state.refcode == '003'?
                                 <div>
                                    <NCRadio value='00101' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>1.入职-附件14劳动合同-新版-新入职员工（点击预览）</NCRadio>
                                    <NCRadio value='00102' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>2.入职-附件16保密协议（全员）（点击预览）</NCRadio>
                                    <NCRadio value='00103' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>3.入职-竞业限制协议（全员版）（点击预览）</NCRadio>
                                    <NCRadio value='00104' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>4.入职-新潮传媒集团员工手册（点击预览）</NCRadio>
                                    <NCRadio value='00105' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>5.入职-经营人员薪酬确认单（点击预览）</NCRadio>
                                    <NCRadio value='00306' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>6.入职-附件18知识产权及保密协议（点击预览）</NCRadio>
                                </div>:
                                //  高管(服务、技术人员)
                                this.state.refcode == '004'?
                                <div>
                                    <NCRadio value='00101' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>1.入职-附件14劳动合同-新版-新入职员工（点击预览）</NCRadio>
                                    <NCRadio value='00102' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>2.入职-附件16保密协议（全员）（点击预览）</NCRadio>
                                    <NCRadio value='00103' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>3.入职-竞业限制协议（全员版）（点击预览）</NCRadio>
                                    <NCRadio value='00104' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>4.入职-新潮传媒集团员工手册（点击预览）</NCRadio>
                                    <NCRadio value='00205' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>5.入职-非经营人员薪酬确认单（点击预览）</NCRadio>
                                    <NCRadio value='00306' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>6.入职-附件18知识产权及保密协议（点击预览）</NCRadio>
                                </div>:
                                // 昆明、玉溪普通人员（销售人员）
                                this.state.refcode == '005'?
                                <div>
                                    <NCRadio value='00102' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>1.入职-附件16保密协议（全员）（点击预览）</NCRadio>
                                    <NCRadio value='00103' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>2.入职-竞业限制协议（全员版）（点击预览）</NCRadio>
                                    <NCRadio value='00104' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>3.入职-新潮传媒集团员工手册（点击预览）</NCRadio>
                                    <NCRadio value='00105' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>4.入职-经营人员薪酬确认单（点击预览）</NCRadio>
                                </div>:
                                // 昆明、玉溪普通人员(服务、技术人员)
                                this.state.refcode == '006'?
                                <div>
                                    <NCRadio value='00102' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>1.入职-附件16保密协议（全员）（点击预览）</NCRadio>
                                    <NCRadio value='00103' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>2.入职-竞业限制协议（全员版）（点击预览）</NCRadio>
                                    <NCRadio value='00104' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>3.入职-新潮传媒集团员工手册（点击预览）</NCRadio>
                                    <NCRadio value='00205' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>4.入职-非经营人员薪酬确认单（点击预览）</NCRadio>
                                </div>:
                                // 昆明、玉溪高管(销售人员)
                                this.state.refcode == '007'?
                                <div>
                                    <NCRadio value='00102' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>2.入职-附件16保密协议（全员）（点击预览）</NCRadio>
                                    <NCRadio value='00103' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>3.入职-竞业限制协议（全员版）（点击预览）</NCRadio>
                                    <NCRadio value='00104' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>4.入职-新潮传媒集团员工手册（点击预览）</NCRadio>
                                    <NCRadio value='00105' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>5.入职-经营人员薪酬确认单（点击预览）</NCRadio>
                                    <NCRadio value='00306' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>6.入职-附件18知识产权及保密协议（点击预览）</NCRadio>
                                </div>:
                                // 昆明、玉溪高管(服务、技术人员)
                                this.state.refcode == '008'?
                                <div>
                                    <NCRadio value='00102' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>1.入职-附件16保密协议（全员）（点击预览）</NCRadio>
                                    <NCRadio value='00103' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>2.入职-竞业限制协议（全员版）（点击预览）</NCRadio>
                                    <NCRadio value='00104' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>3.入职-新潮传媒集团员工手册（点击预览）</NCRadio>
                                    <NCRadio value='00205' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>4.入职-非经营人员薪酬确认单（点击预览）</NCRadio>
                                    <NCRadio value='00306' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>5.入职-附件18知识产权及保密协议（点击预览）</NCRadio>
                                </div>:
                                // 实习生
                                this.state.refcode == '009'?
                                <div>
                                    <NCRadio value='00901' style={{ fontWeight: 'bold', fontSize: '30px' ,margin:'left'}}>1.入职-实习生入职协议（点击预览）</NCRadio>
                                    <NCRadio value='00902' style={{ fontWeight: 'bold', fontSize: '30px' }}>2.入职-实习生保密协议（点击预览）</NCRadio>
                                    <NCRadio value='00104' style={{ fontWeight: 'bold', fontSize: '30px' }}>3.入职-新潮传媒集团员工手册（点击预览）</NCRadio>
                                    <NCRadio value='00904' style={{ fontWeight: 'bold', fontSize: '30px' }}>4.入职-实习生薪酬确认单（点击预览）</NCRadio>
                                </div>:
                                <div>暂无模板</div>
                            }
                                <br></br>
                            </NCRadioGroup>
                        </div>
                    </ModalBody>
                    <ModalFooter>
                        {
                            this.state.isBtnFlag == '01' ?
                                <div>
                                    <NCButton colors="primary" onClick={this.onOk.bind(this, QysChooseModalValue)}>确认</NCButton>
                                    <NCButton onClick={this.onClose}>取消</NCButton>
                                </div> :
                                ''
                        }

                    </ModalFooter>
                </NCModal>
            </div>
        )
    }
}

export default QysChoose;